const resolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const typescript = require("@rollup/plugin-typescript");
const terser = require("@rollup/plugin-terser");
const fs = require("node:fs");
const path = require("node:path");

// 检查目录是否存在，存在删除目录
const distPath = path.join(__dirname, "dist");
if (fs.existsSync(distPath)) {
  fs.rmSync(distPath, { recursive: true });
}

module.exports = {
  // 入口文件
  input: "src/index.ts",
  // 输出文件
  output: [
    // commonjs
    {
      file: "dist/index.cjs.js",
      format: "cjs",
    },
    // es module
    {
      file: "dist/index.esm.js",
      format: "es",
    },
    // umd
    {
      file: "dist/index.umd.js",
      format: "umd",
      name: "cmd-cloud-router",
    },
  ],
  // 排除依赖模块
  external: ["fs", "path", "os"],
  // 使用插件
  plugins: [resolve(), commonjs(), typescript(), terser()],
};
